// 类组件

import { Component } from 'react'

class DemoA extends Component {
    constructor() {
        super();
        this.state = {
            count: 1,
            num: 2
        }
    }
    add(e) {
        console.log(e.currentTarget.getAttribute("data-value"))
        if (e.target.dataset.value) {
            this.setState({
                count: this.state.count + 1,
            })
        } else {
            this.setState({
                num: this.state.num + 2
            })
        }
    }

    render() {
        let { count, num } = this.state
        return (
            <div>
                <h1><span>{count}---{num}</span></h1>
                {/* <button onClick={this.add.bind(this)} data-value='button1'> +1</button > */}
                <button onClick={(e) => this.add(e)} data-value='xxx'> 点我+1</button >
                <button onClick={(e) => this.add(e)}>点我+2</button>
            </div >

        )
    }
}

export default DemoA